<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!--<link rel="stylesheet" href="../plugins/elementui/index.css">-->
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!--<script src="../plugins/elementui/index.js"></script>-->
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置<small>菜单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="菜单名称" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage2()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreateLevel1()">新建一级菜单</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建多级菜单</el-button>
            </div>
            <el-table
                    size="small"
                    row-key="id"
                    :data="dataList"
                    highlight-current-row
                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <!--<el-table-column type="index" align="center" label="序号"></el-table-column>-->
                <el-table-column prop="name" label="菜单名称" align="left"></el-table-column>
                <el-table-column
                        label="图标"
                        width="50"
                        align="center">
                    <template slot-scope="scope">
                        <i class="fa" :class="scope.row.icon" ></i>
                    </template>
                </el-table-column>
                <el-table-column label="菜单等级" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.level == '1' ? '一级菜单' :  '二级菜单'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="priority" label="显示顺序" align="center"></el-table-column>
                <el-table-column prop="path" label="菜单路径" align="center"></el-table-column>
                <el-table-column prop="linkUrl" label="菜单地址" align="center"></el-table-column>
                <el-table-column prop="description" label="菜单详情" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页栏 -->
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增二级菜单弹层 -->
            <div class="add-form">
                <el-dialog title="新建多级菜单" :visible.sync="dialogFormVisible">
                    <!--<template>-->
                    <!--<el-tabs v-model="activeName" type="card">-->
                    <!--<el-tab-pane label="基本信息" name="first">-->
                    <el-form :model="formData" ref="dataAddForm" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="上级目录" prop="parentMenuId">
                                    <el-select placeholder="请选择" v-model="formData.parentMenuId">
                                        <el-option :key="menu.id" :label="menu.name" :value="menu.id" v-for="menu in parentMenu"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单地址">
                                    <el-input v-model="formData.linkUrl"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="图标选择">
                                    <el-select v-model="formData.icon">
                                        <el-option value="el-icon-star-off" ><i class="el-icon-star-off">el-icon-star-off</i></el-option>
                                        <el-option value="el-icon-view" ><i class="el-icon-view">el-icon-view</i></el-option>
                                        <el-option value="el-icon-paperclip" ><i class="el-icon-paperclip">el-icon-paperclip</i></el-option>
                                        <el-option value="el-icon-reading" ><i class="el-icon-reading">el-icon-reading</i></el-option>
                                        <el-option value="el-icon-collection" ><i class="el-icon-collection">el-icon-collection</i></el-option>
                                        <el-option value="el-icon-copy-document" ><i class="el-icon-copy-document">el-icon-copy-document</i></el-option>
                                        <el-option value="el-icon-chat-line-round" ><i class="el-icon-chat-line-round">el-icon-chat-line-round</i></el-option>
                                        <el-option value="el-icon-cpu" ><i class="el-icon-cpu">el-icon-cpu</i></el-option>
                                        <el-option value="el-icon-guide" ><i class="el-icon-guide">el-icon-guide</i></el-option>
                                        <el-option value="el-icon-picture-outline" ><i class="el-icon-picture-outline">el-icon-picture-outline</i></el-option>
                                        <el-option value="el-icon-question" ><i class="el-icon-question">el-icon-question</i></el-option>
                                        <el-option value="el-icon-message-solid" ><i class="el-icon-message-solid">el-icon-message-solid</i></el-option>
                                        <el-option value="el-icon-s-cooperation" ><i class="el-icon-s-cooperation">el-icon-s-cooperation</i></el-option>
                                        <el-option value="el-icon-s-operation" ><i class="el-icon-s-operation">el-icon-s-operation</i></el-option>
                                        <el-option value="el-icon-s-promotion" ><i class="el-icon-s-promotion">el-icon-s-promotion</i></el-option>
                                        <el-option value="el-icon-s-home" ><i class="el-icon-s-home">el-icon-s-home</i></el-option>
                                        <el-option value="el-icon-s-custom" ><i class="el-icon-s-custom">el-icon-s-custom</i></el-option>
                                        <el-option value="el-icon-s-grid" ><i class="el-icon-s-grid">el-icon-s-grid</i></el-option>
                                        <el-option value="el-icon-s-open" ><i class="el-icon-s-open">el-icon-s-open</i></el-option>
                                        <el-option value="el-icon-s-claim" ><i class="el-icon-s-claim">el-icon-s-claim</i></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="显示排序" prop="priority">
                                    <el-input-number v-model="formData.priority" controls-position="right" :min="1" :max="10"></el-input-number>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="菜单详情">
                                    <el-input v-model="formData.description" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!--新增一级菜单弹层-->
            <div class="add-form">
                <el-dialog title="新增一级菜单" :visible.sync="dialogFormVisibleLevel1">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="一级菜单名称">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="图标选择">
                                                <el-select v-model="formData.icon">
                                                    <el-option value="el-icon-star-off" ><i class="el-icon-star-off">el-icon-star-off</i></el-option>
                                                    <el-option value="el-icon-view" ><i class="el-icon-view">el-icon-view</i></el-option>
                                                    <el-option value="el-icon-paperclip" ><i class="el-icon-paperclip">el-icon-paperclip</i></el-option>
                                                    <el-option value="el-icon-reading" ><i class="el-icon-reading">el-icon-reading</i></el-option>
                                                    <el-option value="el-icon-collection" ><i class="el-icon-collection">el-icon-collection</i></el-option>
                                                    <el-option value="el-icon-copy-document" ><i class="el-icon-copy-document">el-icon-copy-document</i></el-option>
                                                    <el-option value="el-icon-chat-line-round" ><i class="el-icon-chat-line-round">el-icon-chat-line-round</i></el-option>
                                                    <el-option value="el-icon-cpu" ><i class="el-icon-cpu">el-icon-cpu</i></el-option>
                                                    <el-option value="el-icon-guide" ><i class="el-icon-guide">el-icon-guide</i></el-option>
                                                    <el-option value="el-icon-picture-outline" ><i class="el-icon-picture-outline">el-icon-picture-outline</i></el-option>
                                                    <el-option value="el-icon-question" ><i class="el-icon-question">el-icon-question</i></el-option>
                                                    <el-option value="el-icon-message-solid" ><i class="el-icon-message-solid">el-icon-message-solid</i></el-option>
                                                    <el-option value="el-icon-s-cooperation" ><i class="el-icon-s-cooperation">el-icon-s-cooperation</i></el-option>
                                                    <el-option value="el-icon-s-operation" ><i class="el-icon-s-operation">el-icon-s-operation</i></el-option>
                                                    <el-option value="el-icon-s-promotion" ><i class="el-icon-s-promotion">el-icon-s-promotion</i></el-option>
                                                    <el-option value="el-icon-s-home" ><i class="el-icon-s-home">el-icon-s-home</i></el-option>
                                                    <el-option value="el-icon-s-custom" ><i class="el-icon-s-custom">el-icon-s-custom</i></el-option>
                                                    <el-option value="el-icon-s-grid" ><i class="el-icon-s-grid">el-icon-s-grid</i></el-option>
                                                    <el-option value="el-icon-s-open" ><i class="el-icon-s-open">el-icon-s-open</i></el-option>
                                                    <el-option value="el-icon-s-claim" ><i class="el-icon-s-claim">el-icon-s-claim</i></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="菜单详情">
                                                <el-input v-model="formData.description" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>

                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisibleLevel1 = false">取消</el-button>
                        <el-button type="primary" @click="handleAddLevel1()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑菜单" :visible.sync="dialogFormVisible4Edit">
                    <!--<template>-->
                    <!--<el-tabs v-model="activeName" type="card">-->
                    <!--<el-tab-pane label="基本信息" name="first">-->
                    <el-form :model="formData" ref="dataEditForm" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="上级目录" prop="parentMenuId">
                                    <el-select placeholder="请选择" v-model="formData.parentMenuId">
                                        <el-option :key="menu.id" :label="menu.name" :value="menu.id" v-for="menu in parentMenu"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单名称" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="菜单地址">
                                    <el-input v-model="formData.linkUrl"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="图标选择">
                                    <el-select v-model="formData.icon">
                                        <el-option value="el-icon-s-tools" ><i class="el-icon-s-tools">el-icon-s-tools</i></el-option>
                                        <el-option value="el-icon-view" ><i class="el-icon-view">el-icon-view</i></el-option>
                                        <el-option value="el-icon-paperclip" ><i class="el-icon-paperclip">el-icon-paperclip</i></el-option>
                                        <el-option value="el-icon-reading" ><i class="el-icon-reading">el-icon-reading</i></el-option>
                                        <el-option value="el-icon-collection" ><i class="el-icon-collection">el-icon-collection</i></el-option>
                                        <el-option value="el-icon-copy-document" ><i class="el-icon-copy-document">el-icon-copy-document</i></el-option>
                                        <el-option value="el-icon-chat-line-round" ><i class="el-icon-chat-line-round">el-icon-chat-line-round</i></el-option>
                                        <el-option value="el-icon-cpu" ><i class="el-icon-cpu">el-icon-cpu</i></el-option>
                                        <el-option value="el-icon-guide" ><i class="el-icon-guide">el-icon-guide</i></el-option>
                                        <el-option value="el-icon-picture-outline" ><i class="el-icon-picture-outline">el-icon-picture-outline</i></el-option>
                                        <el-option value="el-icon-question" ><i class="el-icon-question">el-icon-question</i></el-option>
                                        <el-option value="el-icon-message-solid" ><i class="el-icon-message-solid">el-icon-message-solid</i></el-option>
                                        <el-option value="el-icon-s-cooperation" ><i class="el-icon-s-cooperation">el-icon-s-cooperation</i></el-option>
                                        <el-option value="el-icon-s-operation" ><i class="el-icon-s-operation">el-icon-s-operation</i></el-option>
                                        <el-option value="el-icon-s-promotion" ><i class="el-icon-s-promotion">el-icon-s-promotion</i></el-option>
                                        <el-option value="el-icon-s-home" ><i class="el-icon-s-home">el-icon-s-home</i></el-option>
                                        <el-option value="el-icon-s-custom" ><i class="el-icon-s-custom">el-icon-s-custom</i></el-option>
                                        <el-option value="el-icon-s-grid" ><i class="el-icon-s-grid">el-icon-s-grid</i></el-option>
                                        <el-option value="el-icon-s-open" ><i class="el-icon-s-open">el-icon-s-open</i></el-option>
                                        <el-option value="el-icon-s-claim" ><i class="el-icon-s-claim">el-icon-s-claim</i></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="显示排序" prop="priority">
                                    <el-input-number v-model="formData.priority" controls-position="right" :min="1" :max="100"></el-input-number>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="菜单详情">
                                    <el-input v-model="formData.description" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            parentMenu: [],//上级目录
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            dialogFormVisibleLevel1:false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                parentMenuId: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }],
                priority: [{ required: true, message: '显示排序为必填项', trigger: 'blur' }]
            }
        },
        created() {
            this.findPage();//分页查询
        },
        methods: {
            //初始化页码,即重置当前页数为1
            searchInit(){
                this.pagination.currentPage = 1;
            },
            //初始化条件,即重置当前搜索条件为null
            conditionInit(){
                this.pagination.queryString = null;
            },
            //初始化上级目录列表
            initParentMenu(){
                axios.post('/menu/initParentMenu.do')
                    .then(res=>{
                        this.parentMenu = res.data;
                    })
            },
            //编辑
            handleEdit() {

                //1.关闭弹出窗口
                this.dialogFormVisible4Edit =false;
                //2.提交表单数据 检查组对象+检查项ids
                axios.post("/menu/edit.do",this.formData).then(res=>{
                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? 'success':"error"
                    });
                    //重新刷新页面
                    this.findPage();
                })

            },
            //添加一级菜单
            handleAddLevel1(){
                axios.post('/menu/addLevel1.do',this.formData).then(res=>{

                    this.dialogFormVisibleLevel1 =false;

                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? 'success':"error"
                    });
                    //重新刷新页面
                    this.findPage();
                })
            },
            //添加
            handleAdd () {
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        //2.关闭弹出
                        this.dialogFormVisible = false;
                        //3..发送新增检查项请求
                        axios.post('/menu/add.do',this.formData).then(res=>{
                            //成功回显数据
                            if(res.data.flag){
                                //提示成功
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                //跳转重新查询
                                this.searchInit();
                                this.conditionInit();
                                this.findPage();
                            }
                            //失败错误提示
                            else
                            {
                                this.$message.error(res.data.message);
                            }
                        })
                    }
                });
            },
            findPage2(){
                //查询分页优化提升用户体验
                this.pagination.currentPage = 1;
                var queryPageBean =
                    {
                        currentPage:this.pagination.currentPage, //当前页码
                        pageSize:this.pagination.pageSize, //当前页显示条数
                        queryString:this.pagination.queryString//查询条件
                    }
                ///分页查询
                axios.post('/menu/findPage2.do',queryPageBean).then(res=>{
                    //PageResult
                    this.pagination.total = res.data.total; //响应总记录数
                    this.dataList = res.data.rows; //响应的数据
                })
            },
            //分页查询
            findPage() {
                var queryPageBean =
                    {
                        currentPage:this.pagination.currentPage, //当前页码
                        pageSize:this.pagination.pageSize, //当前页显示条数
                        queryString:this.pagination.queryString//查询条件
                    }
                ///分页查询
                axios.post('/menu/findPage.do',queryPageBean).then(res=>{
                    //PageResult
                    this.pagination.total = res.data.total; //响应总记录数
                    this.dataList = res.data.rows; //响应的数据
                })
            },
            // 重置表单
            resetForm() {
                //清空表单的方法
                //检查组表单
                this.formData={};
                //勾选
                this.checkitemIds=[];
                //选项卡选中
                this.activeName='first';
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                //弹出新增检查组窗口
                this.dialogFormVisible = true;
                //查询检查项列表数据
                this.initParentMenu();//查询所有上级目录
            },// 弹出添加窗口
            handleCreateLevel1() {
                this.resetForm();
                //弹出新增检查组窗口
                this.dialogFormVisibleLevel1 = true;

            },
            // 弹出编辑窗口
            handleUpdate(row) {
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                this.initParentMenu();
                //回显数据 根据检查组id查询检查组数据
                axios.get("/menu/findMenuById.do?menuId="+row.id).then(res=>{
                    this.$message({
                        message: res.data.message,
                        type: res.data.flag ? 'success':"error"
                    });
                    if(res.data.flag) {
                        //如果查询检查组回显成功再显示
                        this.formData = res.data.data;
                    }

                })





            },
            //切换页码
            handleCurrentChange(currentPage) {
                //重新设置页码
                this.pagination.currentPage = currentPage;
                //重新查询就可以得到数据
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                this.$confirm('确认要删除该菜单吗, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送删除请求
                    axios.get('/menu/deleteById.do?id='+row.id).then(res=>{
                        this.$message({
                            message: res.data.message,
                            type: res.data.flag ? 'success':"error"
                        });
                        //重新加载数据
                        this.findPage();
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        }
    })
</script>
</html>
